package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.ProductMapper;
import com.itheima.mapper.SalesItemsMapper;
import com.itheima.mapper.SalesMapper;
import com.itheima.pojo.*;
import com.itheima.service.ProductService;
import com.itheima.service.SalesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * @author 3shy.cn
 * @description SalesServiceImpl
 */

@Service
public class ProductServiceImpl implements ProductService {


    @Autowired
    private ProductMapper  productMapper;
    @Override
    public PageBean page(ProductQueryParam productQueryParam) {
        PageHelper.startPage(productQueryParam.getPage(), productQueryParam.getPageSize());

        //2. 执行查询
        Page<Product> p = (Page<Product>) productMapper.page(productQueryParam);

        //3. 封装结果
        return new PageBean(p.getTotal(), p.getResult());
    }

    @Override
    public void save(Product product) {
        productMapper.insert(product);
    }

    @Override
    public Product getInfo(Integer id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Product product) {
        productMapper.update(product);
    }

    @Override
    public void deletByIds(List<Integer> ids) {
        productMapper.deletByIds(ids);
    }

    @Override
    public List<Product> queryProuctList() {
        return productMapper.queryProuctList();
    }
}
